<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>安平通行码</title>
</head>

<body>
    <!-- 页面顺序 login middle user gocode -->
    <script src="./jquery/jquery.min.js"></script>
    <script>
        // 拿到码上的登记地址和code和type
        var args = new Object();
        var query = decodeURI(location.search.substring(1)); //获取查询串  
        //alert(query)
        var pairs = query.split("&"); //在逗号处断开  
        for (var i = 0; i < pairs.length; i++) {
            var pos = pairs[i].indexOf('='); //查找name=value   
            if (pos == -1) continue; //如果没有找到就跳过   
            var argname = pairs[i].substring(0, pos); //提取name   
            var value = pairs[i].substring(pos + 1); //提取value   
            args[argname] = unescape(value); //存为属性   
        }
        // state是后台传的参数
        var state = args.state;
        // alert(state)
        // code
        var code = args.code;
        var type = "";
        var rukouName = "";
        var status = ""
        var urls = ""; //跳转路径
        // 后台的state参数第一项是位置,第二项是type,用|隔开 '4|4'
        if (state.indexOf('-')) {
            //alert("!!!!"+state.indexOf('|'))
            rukouName = state.substring(0, state.indexOf('-'))
            type = state.substring(state.indexOf('-') + 1)
        }
        //alert('type:'+type)
        // alert('rukouName:'+rukouName)
        // 根据code获取是不是注册过
        if (code) {
            $.ajax({
                url: "http://47.92.216.207:8899/ymtUser/query",
                type: "get",
                data: {
                    wxcode: code
                },
                success: function (res) {
                    if (res.code == 0) {
                        //加一个标识
                        status = 0
                        // alert("注册了!!!")
                    } else {
                        //alert("未注册!!!!")
                        status = 1
                    }
                    if (type == 1) {
                        urls = "http://hesuan.city1000.cn/register/community.html"
                    } else if (type == 2) {
                        urls = "http://hesuan.city1000.cn/register/checkpoint.html"
                    } else if (type == 3) {
                        urls = "http://hesuan.city1000.cn/register/store.html"
                    } else {
                        urls = "http://hesuan.city1000.cn/register/organ.html"
                    }
                    var data=`${rukouName}-${status}`
                    //跳转到用户登记页面(张盼做的转发)
                    window.location.href =
                        'http://user.city1000.cn:9999/weixin/wechat/h5/redirectSomeWhere?url=' + urls +
                        "&data=" + data
                    // window.location.href ='http://www.baidu.com'
                },
                error: function (err) {
                    alert("请您重新进入页面:" + err.status)
                    //window.location.go(-2)
                }
            })
        } else {
            alert("请重新扫码!!!")
        }
    </script>
</body>

</html>